package com.my.blog.controller;

import com.my.blog.domain.ResponseResult;
import com.my.blog.domain.dto.UserAddDto;
import com.my.blog.domain.dto.AdminUserDto;
import com.my.blog.service.IAdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system")
public class AdminUserController {
    @Autowired
    private IAdminUserService adminUserService;

    @GetMapping("/user/list")
    public ResponseResult getUserList(Integer pageNum, Integer pageSize, String userName, String phonenumber, String status) {
        ResponseResult userList = adminUserService.getUserList(pageNum, pageSize, userName, phonenumber, status);
        return userList;
    }

    @GetMapping("/role/listAllRole")
    public ResponseResult getListAllRole() {
        ResponseResult listAllRole = adminUserService.getListAllRole();
        return listAllRole;
    }

    @PostMapping("/user")
    public ResponseResult addUser(@RequestBody UserAddDto userAddDto) {
        return adminUserService.addUser(userAddDto);
    }

    @DeleteMapping("/user/{id}")
    public ResponseResult deleteUserById(@PathVariable Long id) {
        return adminUserService.deleteUser(id);
    }

    @GetMapping("/user/{id}")
    public ResponseResult getUserInfoById(@PathVariable Long id) {
        // 调用服务层方法获取用户信息
        return adminUserService.getUserInfoById(id);
    }

    @PutMapping("/user")
    public ResponseResult updateUserInfo(@RequestBody AdminUserDto adminUserDto){
        return adminUserService.updateUserInfo(adminUserDto);
    }

}
